package multitionPattern;

/**
 * 使用枚举实现的多例模式
 */
public enum EnumMultiton {
    INSTANCE1("实例1"),
    INSTANCE2("实例2"),
    INSTANCE3("实例3");
    
    private final String name;
    
    EnumMultiton(String name) {
        this.name = name;
    }
    
    public String getName() {
        return name;
    }
    
    public void execute() {
        System.out.println(name + " 执行操作");
    }
    
    // 可以通过名称获取枚举实例
    public static EnumMultiton getByName(String name) {
        for (EnumMultiton instance : values()) {
            if (instance.name.equals(name)) {
                return instance;
            }
        }
        throw new IllegalArgumentException("未知实例: " + name);
    }
}